package projects

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
	"xpms/app/models"
)

type ProjectsTestComments struct {
	Id             int64  `orm:"pk;column(commentid);"`
	Testid         int64  `json:"Testid,string"`
	Userid         int64  `json:"Userid,string"`
	UserName       string `orm:"column(username);"`
	Attachmentname string
	Attachment     string
	Comment        string
	Created        int64
}

func (this *ProjectsTestComments) TableName() string {
	return models.TableName("projects_test_comments")
}
func init() {
	orm.RegisterModel(new(ProjectsTestComments))
}

func AddTestComments(upd ProjectsTestComments) error {
	o := orm.NewOrm()
	comment := new(ProjectsTestComments)
	comment.Id = upd.Id
	comment.Testid = upd.Testid
	comment.Userid = upd.Userid
	comment.Comment = upd.Comment
	comment.UserName = upd.UserName
	comment.Attachment = upd.Attachment
	comment.Attachmentname = upd.Attachmentname
	comment.Created = time.Now().Unix()
	_, err := o.Insert(comment)
	return err
}

func ListProjectTestComment(testId int64) (ops []ProjectsTestComments) {
	var comment []ProjectsTestComments
	o := orm.NewOrm()
	qs := o.QueryTable(models.TableName("projects_test_comments"))
	cond := orm.NewCondition()
	if testId > 0 {
		cond = cond.And("testid", testId)
	}
	qs = qs.SetCond(cond)
	qs.All(&comment)

	return comment
}
